package com.itlaobing.demo.util;

import lombok.Data;

import java.io.Serializable;

/**
 * @Classname PageUtil
 * @Description TODO()
 * @Date 2020/11/14 0014 16:15
 * @Author by Administrator
 * @Version v1.0
 */
@Data
public class PageUtil implements Serializable {

    /**
     * 当前页码
     */
    private Integer current;

    /**
     * 一共有多少条数据
     */
    private Integer count;

    /**
     * 是否有下一页
     */
    private Boolean hasNext;

    /**
     * 是否有上一页
     */
    private Boolean hasPrev;

    /**
     * 最后一页的页码
     */
    private Integer last;

    /**
     * 每页多少条数据
     */
    private Integer size;

    public PageUtil(int count){
        this(1, 5, count);
    }

    public PageUtil(int current, int count){
        this(current, 5, count);
    }

    public PageUtil(int current, int size, int count){
        this.current = current;
        this.count = count;
        this.size = size;
        // 最后一页
        last = last();
        // 下一页
        hasNext = current < last ? true : false;
        // 上一页
        hasPrev = current > 1 ? true : false;
    }

    public int last(){
        return (int)Math.ceil(this.count / (size * 1.0));
    }

}
